<?php
/**
 * 导入采集规则
 *
 * @version        $Id: co_get_corule.php 1 17:13 2010年7月12日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require(dirname(__FILE__)."/config.php");

CheckPurview('co_AddNote');
if(empty($job))
{
    $job='';
}
if($job=='')
{
	require_once(DEDEADMIN."/inc/inc_catalog_options.php");
	$typeOptions = GetOptionList(0,$cuserLogin->getUserChannel(),$channelid);


	// huchuan5.com 互传网络 2013.7.17 -------------------------------------------------------------------------
    require_once(DEDEINC."/../include/oxwindow.class.php");
    $wintitle = "导入采集规则";
    $wecome_info = "<a href='co_main.php'><u>采集点管理</u></a>::导入采集规则";
    $win = new OxWindow();
    $win->Init("co_get_corule.php","js/qtaobao.js","POST","qform");
    $win->AddHidden("job","yes");
    $win->AddTitle("关键词:");
    $win->AddMsgItem("<input type='text' name='keywords' value=''/>","height=30");
    $win->AddTitle("价格区间(从低至高)：");
    $win->AddMsgItem("<input type='text' onKeyUp=value=value.replace(/\D+/g,'') style='width:60px;' name='price1' value=''/> 元 <input style='width:60px;' onKeyUp=value=value.replace(/\D+/g,'') type='text' name='price2' value=''/> 元","height=30");
    $win->AddTitle("排序：");
    $win->AddMsgItem("按销量:<input type='checkbox' name='xl' value='1'/> (高-低) &nbsp;&nbsp;按信用<input type='checkbox' name='xy' value='1'/> (高-低)","height=30");
    $win->AddTitle("采集分页：(默认为空，默认只采集第一页)");
	$win->AddMsgItem("页数：<input style='width:30px;' onKeyUp=value=value.replace(/\D+/g,'') type='text' name='duoye' value=''/> <input type='button' onclick='reaseDuoYe()'value='清空' /> 注：40-50个商品/页,共100页(以淘宝网实际显示为准!)","height=30");
    $win->AddTitle("采集网址预览：");
    $win->AddMsgItem("<input type='button' onclick='CheckSubmit();' value='生成预览网址'> <span id='pdisplay'></span>&nbsp;<span id='popen'> </span> <input onclick='copyText();' name='copyText' value='复制' type='hidden'/>","height=30");
    $win->AddTitle("请在下面输入你要导入的文本配置:(以下为自动生成内容，可酌情修改！)");
	$win->SetCheckScript("document.getElementById('notes').value='d'");
    $win->AddMsgItem("节点名称：<select name='qtitleclass' id='qtitleclass'>\r\n<option value='0' selected>从网站栏目中选择...</option>\r\n$typeOptions</select> <input type='button' onclick='CheckSubmit();Ctextarea();' value='生成配置'> 自定义:<input type='text' name='qtitle' id='qtitle' value=''/> 注：如果两者都存在，系统将首选自定义！","height=30");
    $win->AddMsgItem("<textarea name='notes' id='notes' style='width:100%;height:120px'></textarea>");
    $winform = $win->GetWindow("ok");
    $win->Display();
    exit();
	
}
else
{
	if(!empty($qtitle)){
		$typeid=1;
	}else{
		$typeid=$qtitleclass;
	}
	// balx@qq.com end 2013.7.17 ---------------------------------------------------------------------------------------
	
    CheckPurview('co_AddNote');
    require_once(DEDEINC."/dedetag.class.php");
    $notes = trim($notes);
	
    //对Base64格式的规则进行解码
    if(ereg('^BASE64:',$notes))
    {
        if(!ereg(':END$',$notes))
        {
            ShowMsg('该规则不合法，Base64格式的采集规则为：BASE64:base64编码后的配置:END !','-1');
            exit();
        }
        $notess = explode(':',$notes);
        $notes = $notess[1];
        $notes = base64_decode(ereg_replace("[\r\n\t ]",'',$notes)) OR die('配置字符串有错误！');
    }
    else
    {
        $notes = stripslashes($notes);
    }
    $dtp = new DedeTagParse();
    $dtp->LoadString($notes);
    if(!is_array($dtp->CTags))
    {
        ShowMsg('该规则不合法，无法导入!','-1');
        exit();
    }
    $ctag1 = $dtp->GetTagByName('listconfig');
    $ctag2 = $dtp->GetTagByName('itemconfig');
    $listconfig = $ctag1->GetInnerText();
    $itemconfig = addslashes($ctag2->GetInnerText());
    $dtp->LoadString($listconfig);
    $listconfig = addslashes($listconfig);
    $noteinfo = $dtp->GetTagByName('noteinfo');
    if(!is_object($noteinfo))
    {
        ShowMsg("该规则不合法，无法导入!","-1");
        exit();
    }
    foreach($noteinfo->CAttribute->Items as $k=>$v)
    {
        $$k = addslashes($v);
    }
    $uptime = time();
    if(empty($freq))
    {
        $freq = 1;
    }
    if(empty($extypeid))
    {
        $extypeid = 0;
    }
    if(empty($islisten))
    {
        $islisten = 0;
    }
    $inquery = " INSERT INTO `#@__co_note`(`channelid`,`notename`,`sourcelang`,`uptime`,`cotime`,`pnum`,`isok`,`usemore`,`listconfig`,`itemconfig`,`typeid`)
               VALUES ('$channelid','$notename','$sourcelang','$uptime','0','0','0','$usemore','$listconfig','$itemconfig','$typeid'); ";
    $rs = $dsql->ExecuteNoneQuery($inquery);
    if(!$rs)
    {
        ShowMsg("保存信息时出现错误！".$dsql->GetError(),"-1");
        exit();
    }
    ShowMsg("成功导入一个规则!","co_main.php");
    exit();
}

?>